package com.fxsh.learn.websocket;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping(value="webSocketByTomcat/serviceToClient")
public class WsController {
	private WebSocket websocket = new WebSocket();
	@GetMapping("index")
	public String index(){
		return "ws";
	}

//	@RequestMapping
//	@PostMapping("sendMsg")
//	public void sendMsg(HttpServletRequest request, HttpServletResponse response) throws IOException {
//		JSONObject json = new JSONObject();
//		json.put("to", request.getSession().getId());
//		json.put("msg", "欢迎连接WebSocket！！！！");
//		websocket.onMessage(json.toJSONString());
//	}
}
